package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 分类持久层接口
 * @author msi
 */
@Mapper
public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 查找分类列表
     * @return 返回分类列表
     */
    @Select("select id, type, name, sort, create_time, update_time, " +
            "create_user, update_user from reggie.category order by sort asc ")
    List<Category> selectList();

    /**
     * 以类型查找分类列表
     * @param type 类型1菜粕 2套餐
     * @return 分类列表
     */
    @Select("select id, type, name, sort, create_time, update_time," +
            " create_user, update_user from reggie.category where type=#{type} order by sort asc")
    List<Category> selectListByType(Integer type);

    /**
     * 分页查询
     * @param index 索引
     * @param pageSize 每页数据大小
     * @return 分页列表
     */
    @Select("select id, type, name, sort, create_time, update_time," +
            "create_user, update_user from reggie.category order by sort asc limit #{index},#{pageSize}")
    List<Category> selectPages(long index,long pageSize);

    /**
     * 查询总量
     * @return 返回总数
     */
    @Select("select count(*) from reggie.category ")
    long getTotal();
}
